package com.nageoffer.shortlink.admin.toolkit;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {

        private static final String SECRET_KEY = "Y3h5enpo";
        private static final long EXPIRATION_TIME = 12*60*60*1000;

        public static String generateToken(Map<String,Object> claims){
            return Jwts.builder()
                    .addClaims(claims)
                    .setExpiration(new Date(System.currentTimeMillis()+EXPIRATION_TIME))
                    .signWith(SignatureAlgorithm.HS256,SECRET_KEY)
                    .compact();
        }

        public static Claims parseToken(String token) throws Exception{
            return Jwts.parser()
                    .setSigningKey(SECRET_KEY)
                    .parseClaimsJws(token)
                    .getBody();
        }
}
